#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define VEC_SZ 20
#define STR_SZ 40

#define DEBUG

#define PEGAR_VETOR(F, I, V)                           \
  while ((c = fgetc(F)) != EOF) {                      \
    i = 1;                                             \
    if (I == VEC_SZ)                                   \
      break;                                           \
    else if (c == '\n')                                \
      continue;                                        \
    else {                                             \
      V[I][0] = c;                                     \
      while (((c = fgetc(F)) != '\n') && (c != EOF)) { \
        if (i == STR_SZ) break;                        \
        else V[I][i++] = c;                            \
      }                                                \
      V[I++][i] = '\0';                                \
    }                                                  \
  }                                            

int main(int argc, char ** argv) {
  char gab[VEC_SZ][STR_SZ + 1];
  char tst[VEC_SZ][STR_SZ + 1];
  FILE * gabf;
  FILE * tstf;
  int gc, tc, i, j, c, btd, f01, f10, f00, f11, flag;

  if (argc != 3) {
    fprintf(stderr, "Use: stat <arq_gabarito> <arq_teste>\n");
    exit(1);
  }

  if ((gabf = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Erro de leitura: %s\n", argv[1]);
    exit(1);
  }

  if ((tstf = fopen(argv[2], "r")) == NULL) {
    fprintf(stderr, "Erro de leitura: %s\n", argv[2]);
    (void) fclose(gabf);
    exit(1);
  }

  gc = tc = 0;
  PEGAR_VETOR(gabf, gc, gab);
  PEGAR_VETOR(tstf, tc, tst);
  
  fclose(gabf);
  fclose(tstf);
  
  f11 = f01 = f10 = f00 = 0;
  for (j = tc - 1; j >= 0; j--) {
    flag = 0;
    for (i = gc - 1; i >= 0; i--)
      if (!strcmp(tst[j], gab[i])) {
	f11++;
	flag = 1;
	break;
      }
      if (!flag) f10++;
  }
    
  for (j = gc - 1; j >= 0; j--) {
    flag = 0;
    for (i = tc - 1; i >= 0; i--)
      if (!strcmp(gab[j], tst[i])) {
        flag = 1;
	    break;
      }
	if (!flag) f01++;
  }

  #ifdef DEBUG
    printf("%d %d %d\n", f11, f10, f01);
  #endif
    
  printf("%.2f%%\n", (gc) ? (100.0 * f11 / (f01 + f10 + f11)) : 0.0);

  return 0;
}

